package com.automobile.backstage.controller;

import com.automobile.backstage.dao.SugestDao;
import com.automobile.backstage.domain.MakeApp;
import com.automobile.backstage.domain.Sugest;
import com.automobile.backstage.service.SugestService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("/sugest")
public class SugestController {
	
	@Autowired
	private SugestService sugestService;
	
	@RequestMapping("/message")
	public @ResponseBody int message(String message) {
		if(message==null) {
			return 0;
		}
        sugestService.newSugest(message);
		return 1;
	}

    @RequestMapping("/findAll")
    public @ResponseBody PageInfo findAll(@RequestParam(value = "page",required = true,defaultValue = "1")Integer page,
                     @RequestParam(value = "size",required = true,defaultValue = "10")Integer size) throws Exception {
        List<Sugest> sugests = sugestService.findAll(page, size);
        PageInfo pageInfo = new PageInfo(sugests);
        return pageInfo;
    }

    @RequestMapping("/del")
    public @ResponseBody int del(@RequestBody List<Integer> ids) throws Exception {
	    sugestService.del(ids);
	    return 1;
    }

    @RequestMapping("/findById")
    public @ResponseBody Sugest findById(@RequestBody int id) throws Exception {
        Sugest sugest = sugestService.findById(id);
        return sugest;
    }
	
}
